﻿package org.hyy.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import org.hyy.base.DatabaseConnection;
import org.hyy.vo.User;

public class AdminDAO {
	private DatabaseConnection dbc;
	private Connection con;				//数据库连接对象
	private PreparedStatement ps;		//预编译对象，用来执行SQL语句
	private ResultSet rs;
	
	/**
	 * 显示所有会员
	 * @return
	 */
	public List showall(){
		List users = null;
		User user;
		//打开数据库
		dbc = new DatabaseConnection();
		con = dbc.getCon();
		//操作数据库
		String sql = "select * from user";
		
		try {
			ps = con.prepareStatement(sql);
			
			rs = ps.executeQuery();
			
			users = new ArrayList();
			//取出对象
			while(rs.next()){
				user = new User(rs.getInt("id"),rs.getString("username"),rs.getString("password"),rs.getString("phone"),rs.getString("addr"),rs.getDate("rdate"));
				users.add(user);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			//关闭数据库
			dbc.close(con);
			dbc = null;
		}
		return users;
	}
}
